# -*- coding: utf-8 -*-
# Array
# 对于较大的array，这种in-place修改能够比用生成器创建一个新的array至少提升15%的速度。
import array
from timeit import Timer
 
def arraytest():
    a = array.array("i", [1, 2, 3, 4, 5])
    b = array.array(a.typecode, (2 * x for x in a))
 
def enumeratetest():
    a = array.array("i", [1, 2, 3, 4, 5])
    for i, x in enumerate(a):
        a[i] = 2 * x
 
if __name__=='__main__':
    m = Timer("arraytest()", "from __main__ import arraytest")
    n = Timer("enumeratetest()", "from __main__ import enumeratetest")
    
print m.timeit() # 2.73459659807
print n.timeit() # 2.01928320198
    